﻿using System;
using System.Data;

namespace Besture.Common
{
    public class BaseDataAccessExt
    {
        /// <summary>
        /// Get information from DataBase ,and return it by datatable
        /// </summary>
        /// <param name="sql">sql</param>
        /// <returns></returns>
        public DataTable GetDataTable(string sql)
        {
            var baseDataAccess = new BaseDataAccess();
            var table =  baseDataAccess.GetDataTable(sql);
            baseDataAccess.CloseConnection();
            return table;
        }
        /// <summary>
        /// Execute Sql query without parameter
        /// </summary>
        /// <param name="sql">sql</param>
        public int ExecuteNonQuery(string sql)
        {
            int number;
            var baseDataAccess = new BaseDataAccess();
            try
            {
                number = baseDataAccess.ExecuteNonQuery(sql);
                baseDataAccess.Commit();
            }
            catch (Exception)
            {
                number = -1;
                baseDataAccess.RollBack();
                throw;
            }
            finally
            {
                baseDataAccess.CloseConnection();
            }
            return number;
        }

        /// <summary>
        /// Execute Sql query without parameter
        /// </summary>
        /// <param name="sql">sql</param>
        public string ExceuteSclar(string sql)
        {
            var baseDataAccess = new BaseDataAccess();
            var str = baseDataAccess.ExecuteScalar(sql);
           baseDataAccess.CloseConnection();
           return str;
        }
    }
}
